package com.csht.facelib.utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import org.greenrobot.greendao.annotation.NotNull;

/**
 * Created by Administrator on 2017/3/20 0020.
 */
public class Tools {

    /**
     * 关闭软键盘
     * @param activity
     */
    public static void hideKeyBoard(@NotNull View view, Activity activity){
        if (view != null){
            view.setFocusable(false);
            view.setFocusableInTouchMode(false);
            view.requestFocus();
            view.findFocus();
        }
        InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if(imm != null) {
            imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
        }
    }

    /**
     * 打开软键盘
     * @param activity
     */
    public static void showKeyBoard(View view,Activity activity){
        if (view != null){
            view.setFocusable(true);
            view.setFocusableInTouchMode(true);
            view.requestFocus();
            view.findFocus();
            InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
            if(imm != null) {
                imm.showSoftInput(view,InputMethodManager.SHOW_FORCED);
            }
        }
    }
}
